@OADA/types
This package is TypeScript type definitions for known OADA formats.
These type are based on OADA/formats.
Installation
yarn add @oada/types
Usage
The type definiton for a given format can be imported based on its $id
.
For example, the OADA Bookmarks v1 format can be imported like so:
import Bookmarks from '@oada/types/oada/bookmarks/v1';
Runtime Validation
Since the formats are backed by schemas,
it is possible to check data against a format at runtime.
All the types in this package export methods for doing so
which are typed properly for TypeScript to understand their type implications.
import Bookmarks, {is, assert} from '@oada/types/oada/bookmarks/v1'
const data1: any =
if (is(data1)) {
const bookmarks: Bookmarks = data1
}
const data2: any =
assert(data2)
const bookmarks: Bookmarks = data2